#ifndef TABMANAGER_H
#define TABMANAGER_H

#include <QTabWidget>
#include <QMap>
#include <QSqlDatabase>

class SqlEditor;

class TabManager : public QTabWidget
{
    Q_OBJECT

public:
    explicit TabManager(QWidget *parent = nullptr);
    
    int addQueryTab(const QString &title = QString());
    void removeQueryTab(int index);
    SqlEditor* getSqlEditor(int index) const;
    SqlEditor* getCurrentSqlEditor() const;

    // 新增方法：启用或禁用自动补全功能
    void setAutoCompletionEnabled(bool enable);

signals:
    void tabAdded(int index);
    void tabRemoved(int index);
    void currentTabChanged(int index);
    
private slots:
    void onTabCloseRequested(int index);
    void onCurrentTabChanged(int index);
    // 新增私有槽函数：处理自动补全相关逻辑
    void handleAutoCompletion();

private:
    void setupUI();
    void setupAutoCompletion();  // 初始化自动补全功能
```cpp
    void setupUI();
    
    void setDatabase(const QSqlDatabase &db);
    
signals:
    void tabAdded(int index);
    void tabRemoved(int index);
    void currentTabChanged(int index);
    
public slots:
    void executeQuery(const QString &query);
    void showQueryResults(class QSqlQueryModel *model);

private slots:
    void onTabCloseRequested(int index);
    void onCurrentTabChanged(int index);

private:
    void setupUI();
    
    QSqlDatabase m_database;
    QMap<int, SqlEditor*> m_editors;
    int m_tabCounter;
};

#endif // TABMANAGER_H